Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward-compatibly deny drops in constants if they *could* actually run. #43932

Merged
merged 3 commits into from
Aug 30, 2017

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Aug 17, 2017

This is part of #40036, specifically the checks for user-defined destructor invocations on locals which may not have been moved away, the motivating example being:

const FOO: i32 = (HasDrop {...}, 0).1;

The evaluation of constant MIR will continue to create 'static slots for more locals than is necessary (if Storage{Live,Dead} statements are ignored), but it shouldn't be misusable.

r? @nikomatsakis

@eddyb eddyb added the S-waiting-on-crater Status: Waiting on a crater run to be completed. label Aug 17, 2017
// Deny *any* live drops anywhere other than functions.
if self.mode != Mode::Fn {
// HACK(eddyb) Emulate a bit of dataflow analysis,
// conservatively, that drop elaboration will do.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really "drop elaboration" dataflow - drop elaboration does not know that None has no destructor - but rather "const qual" dataflow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it's a combination of the two.

@eddyb
Copy link
Member Author

eddyb commented Aug 17, 2017

@bors try (for cargobomb)

@bors
Copy link
Contributor

bors commented Aug 17, 2017

⌛ Trying commit cdfe8d7 with merge f6c35c6...

bors added a commit that referenced this pull request Aug 17, 2017
Forward-compatibly deny drops in constants if they *could* actually run.

This is part of #40036, specifically the checks for user-defined destructor invocations on locals which *may not* have been moved away, the motivating example being:
```rust
const FOO: i32 = (HasDrop {...}, 0).1;
```
The evaluation of constant MIR will continue to create `'static` slots for more locals than is necessary (if `Storage{Live,Dead}` statements are ignored), but it shouldn't be misusable.

r? @nikomatsakis
@bors
Copy link
Contributor

bors commented Aug 17, 2017

☀️ Test successful - status-travis
State: approved= try=True

@eddyb
Copy link
Member Author

eddyb commented Aug 17, 2017

cc @rust-lang/infra Cargobomb run requested.

@aidanhs
Copy link
Member

aidanhs commented Aug 18, 2017

Cargobomb run started

@nikomatsakis
Copy link
Contributor

Any news from cargobomb run?

@aidanhs
Copy link
Member

aidanhs commented Aug 22, 2017

~27 hours remaining. I was away for the weekend so didn't manage to kick off a phase of the run until yesterday.

@aidanhs
Copy link
Member

aidanhs commented Aug 23, 2017

At long last - http://cargobomb-reports.s3.amazonaws.com/pr-43932/index.html

@eddyb
Copy link
Member Author

eddyb commented Aug 24, 2017

Great, only regression is Rocket (which I've seen on crater before). However, I've changed by mind about it - it only uses associated const in inherent impls and we should probably treat those the same as const items - since there is no trait-like type dispatch being involved.

@alexcrichton alexcrichton added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Aug 24, 2017
@alexcrichton
Copy link
Member

Switching to S-waiting-on-review as looks like cargobomb's been run, cc @nikomatsakis

@eddyb eddyb added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 24, 2017
@eddyb
Copy link
Member Author

eddyb commented Aug 24, 2017

Also waiting on me to treat inherent associated consts the same as const items.

@eddyb eddyb force-pushed the const-scoping branch 5 times, most recently from 52667d8 to 8697b80 Compare August 27, 2017 12:11
@eddyb
Copy link
Member Author

eddyb commented Aug 27, 2017

Latest crater report confirms Rocket has been fixed. r? @nikomatsakis

@eddyb eddyb removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 27, 2017
@arielb1
Copy link
Contributor

arielb1 commented Aug 27, 2017

@eddyb

Could you add a test for the rocket case, so we can make sure it stays fixed?

// HACK(eddyb) Emulate a bit of dataflow analysis,
// conservatively, that drop elaboration will do.
let needs_drop = if let Lvalue::Local(local) = *lvalue {
self.local_needs_drop[local]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume that we will reject (for constants) things that mutate "MIR locals" once they are assigned?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that is considered an assignment and disallowed as "statement-like".

fn drop(&mut self) {}
}

static FOO: Option<&'static WithDtor> = Some(&WithDtor);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a test with struct WithoutDtor and Some(&WithoutDtor)? Does that behave differently?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That has worked since 1.0, but if you have something more advanced in mind that would actually stress the new code, I'm up for it.

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable. I left a few questions.

@nikomatsakis
Copy link
Contributor

(To be clear, I want to revisit shortly once I see answers.)

@nikomatsakis
Copy link
Contributor

@eddyb would you mind adding a few more tests, just to have more "exhaustive" coverage of the various cases? otherwise, r=me I think.

@nikomatsakis
Copy link
Contributor

@bors r+ -- after some discussion with @eddyb on IRC, decided tests are "good enough".

@bors
Copy link
Contributor

bors commented Aug 30, 2017

📌 Commit c76a024 has been approved by nikomatsakis

@nikomatsakis nikomatsakis added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 30, 2017
@bors
Copy link
Contributor

bors commented Aug 30, 2017

⌛ Testing commit c76a024 with merge 7eeac1b...

bors added a commit that referenced this pull request Aug 30, 2017
Forward-compatibly deny drops in constants if they *could* actually run.

This is part of #40036, specifically the checks for user-defined destructor invocations on locals which *may not* have been moved away, the motivating example being:
```rust
const FOO: i32 = (HasDrop {...}, 0).1;
```
The evaluation of constant MIR will continue to create `'static` slots for more locals than is necessary (if `Storage{Live,Dead}` statements are ignored), but it shouldn't be misusable.

r? @nikomatsakis
@bors
Copy link
Contributor

bors commented Aug 30, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 7eeac1b to master...

@bors bors merged commit c76a024 into rust-lang:master Aug 30, 2017
@eddyb eddyb deleted the const-scoping branch August 31, 2017 05:10
bors added a commit that referenced this pull request Sep 3, 2017
Better StorageLive / StorageDead placement for constants.

Fixes problems in miri (see rust-lang/miri#324 (comment)) caused by the new scope rules in #43932.
What I've tried to do here is always have a `StorageLive` but no `StorageDead` for `'static` slots.
It might not work perfectly in all cases, but it should unblock miri.

r? @nikomatsakis cc @oli-obk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants